//
//  AMNewFeatureController.m
//  AMwb
//
//  Created by zhc on 15/11/30.
//  Copyright © 2015年 zhc. All rights reserved.
//

#import "AMNewFeatureController.h"
#import "AMTabBarViewController.h"
#define AMnewfeatueCount 4

@interface AMNewFeatureController()<UIScrollViewDelegate>

@property(nonatomic,weak) UIPageControl*pageControl;

@end


@implementation AMNewFeatureController

- (void)viewDidLoad{

   //1.创建一个scrollView
    
    
    UIScrollView *scrollView=[[UIScrollView alloc]init];
    scrollView.frame =self.view.bounds;
   
    scrollView.pagingEnabled=YES;
    [self.view addSubview:scrollView];
    
    //2.添加imageView
    CGFloat scrollW=scrollView.width;
    CGFloat scrollH=scrollView.height;
   
   
    
    for(int i=0;i<AMnewfeatueCount;i++){
        UIImageView *sview=[[UIImageView alloc]init];
        sview.height=scrollH;
        sview.width=scrollW;
        sview.y=0;
        sview.x=i*scrollW;
        
        NSString *name=[NSString stringWithFormat:@"new_feature_%d",i+1];
        sview.image=[UIImage imageNamed:name];
         [scrollView addSubview:sview];
        
        if(i == AMnewfeatueCount-1)
        {
           [self setupLastImageView:sview];
        
        
        
        
        }
        
        
        
        
    }
        //3.设置scroll的属性
        scrollView.bounces=NO;
        scrollView.showsHorizontalScrollIndicator=NO;
    
      scrollView.contentSize=CGSizeMake(AMnewfeatueCount*scrollW, 0);
  
    scrollView.delegate=self;
        //4.设置pageControl
        
        UIPageControl *pageControl=[[UIPageControl alloc]init];
       
        pageControl.centerX=scrollW*0.5;
        pageControl.y=scrollH-50;
        pageControl.pageIndicatorTintColor=[UIColor grayColor];
        pageControl.currentPageIndicatorTintColor=[UIColor orangeColor];
        
        
        pageControl.backgroundColor=[UIColor redColor];
        pageControl.numberOfPages=AMnewfeatueCount;
       // pageControl.currentPage=
        self.pageControl=pageControl;
    
        [self.view addSubview:pageControl];
   

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
   int page=scrollView.contentOffset.x/scrollView.width+0.5;
       
    self.pageControl.currentPage = page;
    
   

}

- (void)setupLastImageView:(UIImageView *)imageView{
    //分享给大家(checkbox)
    UIButton *shareBtn=[[UIButton alloc]init];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [shareBtn setTitle:@"分享给大家" forState: UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    shareBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    shareBtn.width=250;
    shareBtn.height=30;
    shareBtn.centerX=imageView.width*0.5;
    shareBtn.centerY=imageView.height*0.65;
    //上左下右  ，切掉对应方向的量，然后从切割的边缘开始
    shareBtn.contentEdgeInsets=UIEdgeInsetsMake(0, 0, 0, 0);//整体切
    shareBtn.titleEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);//文字切
    shareBtn.imageEdgeInsets=UIEdgeInsetsMake(0, 0, 0, 20);//图片切
    
    
    
    [imageView addSubview:shareBtn];
    [shareBtn addTarget:self action:@selector(shareBtnclick:) forControlEvents:UIControlEventTouchUpInside];
   // shareBtn.userInteractionEnabled=YES;
    imageView.userInteractionEnabled=YES;
    UIButton *startBtn=[[UIButton alloc]init];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    
    
    [startBtn setTitle:@"开始微博" forState:UIControlStateNormal];
    [startBtn addTarget:self action:@selector(startBtnclick) forControlEvents:UIControlEventTouchUpInside];
    startBtn.width=120;
    startBtn.height=40;
    
    startBtn.centerX=shareBtn.centerX;
    startBtn.y=imageView.height*0.75;
    [imageView addSubview:startBtn];
    
    
    
    
    


}

- (void)startBtnclick{
  //切换控制器的方法 1. push，依赖导航控制器，可逆
  //2.modal,可逆，A->B  ,B->A
  //3. 切换windo的rootviewController,能进入下一个界面，而且当前界面销毁了，不可逆
//    
    UIWindow *window=[UIApplication sharedApplication].keyWindow;
    window.rootViewController=[[AMTabBarViewController alloc]init];


//    AMTabBarViewController *tVC=[[AMTabBarViewController alloc]init];
//    [self presentViewController:tVC animated:YES completion:nil];
//    

}


- (void)dealloc{

    AMLog(@"qule ");

}


- (void)shareBtnclick:(UIButton *)shareBtn{
    
    
    
    shareBtn.selected=!shareBtn.selected;


}





@end
